#include "ed_core/resultdegree.h"

using namespace ed_core;

ResultDegree* ResultDegree::_instance = nullptr;

ResultDegree::ResultDegree()
{
  initResultDegreeMap();
}

ResultDegree *ResultDegree::inst()
{
  if (_instance == nullptr) _instance = new ResultDegree();
  return _instance;
}

ResultDegree::Degree ResultDegree::check(quint32 result, quint32 difficulty)
{
  if (difficulty < 2 || difficulty >= (quint32)_resultDegrees.size()) return Undefined;

  int degree = (int)Pathetic;
  // Iterate over possible result degrees (in ascending order).
  for (; degree <= (int)Extraordinary; ++degree)
  {
    // If the result is lower than the minimum value required for the current degree.
    if (result < _resultDegrees[difficulty][(Degree)degree]) break;
  }
  // We are one step further than the expected result
  return (Degree)(degree-1);
}

void ResultDegree::initResultDegreeMap()
{
  _resultDegrees.resize(52);
  _resultDegrees[2][Pathetic] = 0;
  _resultDegrees[2][Mediocre] = 1;
  _resultDegrees[2][Average] = 2;
  _resultDegrees[2][Good] = 5;
  _resultDegrees[2][Excellent] = 7;
  _resultDegrees[2][Extraordinary] = 9;
  _resultDegrees[3][Pathetic] = 0;
  _resultDegrees[3][Mediocre] = 1;
  _resultDegrees[3][Average] = 3;
  _resultDegrees[3][Good] = 6;
  _resultDegrees[3][Excellent] = 8;
  _resultDegrees[3][Extraordinary] = 10;
  _resultDegrees[4][Pathetic] = 0;
  _resultDegrees[4][Mediocre] = 1;
  _resultDegrees[4][Average] = 4;
  _resultDegrees[4][Good] = 7;
  _resultDegrees[4][Excellent] = 10;
  _resultDegrees[4][Extraordinary] = 12;
  _resultDegrees[5][Pathetic] = 0;
  _resultDegrees[5][Mediocre] = 1;
  _resultDegrees[5][Average] = 5;
  _resultDegrees[5][Good] = 9;
  _resultDegrees[5][Excellent] = 11;
  _resultDegrees[5][Extraordinary] = 14;
  _resultDegrees[6][Pathetic] = 1;
  _resultDegrees[6][Mediocre] = 2;
  _resultDegrees[6][Average] = 6;
  _resultDegrees[6][Good] = 10;
  _resultDegrees[6][Excellent] = 13;
  _resultDegrees[6][Extraordinary] = 17;
  _resultDegrees[7][Pathetic] = 1;
  _resultDegrees[7][Mediocre] = 2;
  _resultDegrees[7][Average] = 7;
  _resultDegrees[7][Good] = 12;
  _resultDegrees[7][Excellent] = 15;
  _resultDegrees[7][Extraordinary] = 19;
  _resultDegrees[8][Pathetic] = 1;
  _resultDegrees[8][Mediocre] = 3;
  _resultDegrees[8][Average] = 8;
  _resultDegrees[8][Good] = 13;
  _resultDegrees[8][Excellent] = 16;
  _resultDegrees[8][Extraordinary] = 20;
  _resultDegrees[9][Pathetic] = 1;
  _resultDegrees[9][Mediocre] = 4;
  _resultDegrees[9][Average] = 9;
  _resultDegrees[9][Good] = 14;
  _resultDegrees[9][Excellent] = 18;
  _resultDegrees[9][Extraordinary] = 22;
  _resultDegrees[10][Pathetic] = 1;
  _resultDegrees[10][Mediocre] = 5;
  _resultDegrees[10][Average] = 10;
  _resultDegrees[10][Good] = 15;
  _resultDegrees[10][Excellent] = 19;
  _resultDegrees[10][Extraordinary] = 24;
  _resultDegrees[11][Pathetic] = 1;
  _resultDegrees[11][Mediocre] = 5;
  _resultDegrees[11][Average] = 11;
  _resultDegrees[11][Good] = 17;
  _resultDegrees[11][Excellent] = 21;
  _resultDegrees[11][Extraordinary] = 25;
  _resultDegrees[12][Pathetic] = 1;
  _resultDegrees[12][Mediocre] = 6;
  _resultDegrees[12][Average] = 12;
  _resultDegrees[12][Good] = 18;
  _resultDegrees[12][Excellent] = 22;
  _resultDegrees[12][Extraordinary] = 27;
  _resultDegrees[13][Pathetic] = 1;
  _resultDegrees[13][Mediocre] = 6;
  _resultDegrees[13][Average] = 13;
  _resultDegrees[13][Good] = 20;
  _resultDegrees[13][Excellent] = 24;
  _resultDegrees[13][Extraordinary] = 29;
  _resultDegrees[14][Pathetic] = 1;
  _resultDegrees[14][Mediocre] = 7;
  _resultDegrees[14][Average] = 14;
  _resultDegrees[14][Good] = 21;
  _resultDegrees[14][Excellent] = 26;
  _resultDegrees[14][Extraordinary] = 32;
  _resultDegrees[15][Pathetic] = 1;
  _resultDegrees[15][Mediocre] = 8;
  _resultDegrees[15][Average] = 15;
  _resultDegrees[15][Good] = 22;
  _resultDegrees[15][Excellent] = 27;
  _resultDegrees[15][Extraordinary] = 33;
  _resultDegrees[16][Pathetic] = 1;
  _resultDegrees[16][Mediocre] = 8;
  _resultDegrees[16][Average] = 16;
  _resultDegrees[16][Good] = 24;
  _resultDegrees[16][Excellent] = 29;
  _resultDegrees[16][Extraordinary] = 35;
  _resultDegrees[17][Pathetic] = 1;
  _resultDegrees[17][Mediocre] = 9;
  _resultDegrees[17][Average] = 17;
  _resultDegrees[17][Good] = 25;
  _resultDegrees[17][Excellent] = 30;
  _resultDegrees[17][Extraordinary] = 37;
  _resultDegrees[18][Pathetic] = 1;
  _resultDegrees[18][Mediocre] = 10;
  _resultDegrees[18][Average] = 18;
  _resultDegrees[18][Good] = 26;
  _resultDegrees[18][Excellent] = 32;
  _resultDegrees[18][Extraordinary] = 38;
  _resultDegrees[19][Pathetic] = 1;
  _resultDegrees[19][Mediocre] = 11;
  _resultDegrees[19][Average] = 19;
  _resultDegrees[19][Good] = 27;
  _resultDegrees[19][Excellent] = 33;
  _resultDegrees[19][Extraordinary] = 39;
  _resultDegrees[20][Pathetic] = 1;
  _resultDegrees[20][Mediocre] = 12;
  _resultDegrees[20][Average] = 20;
  _resultDegrees[20][Good] = 28;
  _resultDegrees[20][Excellent] = 34;
  _resultDegrees[20][Extraordinary] = 41;
  _resultDegrees[21][Pathetic] = 1;
  _resultDegrees[21][Mediocre] = 13;
  _resultDegrees[21][Average] = 21;
  _resultDegrees[21][Good] = 29;
  _resultDegrees[21][Excellent] = 35;
  _resultDegrees[21][Extraordinary] = 42;
  _resultDegrees[22][Pathetic] = 1;
  _resultDegrees[22][Mediocre] = 13;
  _resultDegrees[22][Average] = 22;
  _resultDegrees[22][Good] = 31;
  _resultDegrees[22][Excellent] = 37;
  _resultDegrees[22][Extraordinary] = 44;
  _resultDegrees[23][Pathetic] = 1;
  _resultDegrees[23][Mediocre] = 14;
  _resultDegrees[23][Average] = 23;
  _resultDegrees[23][Good] = 32;
  _resultDegrees[23][Excellent] = 38;
  _resultDegrees[23][Extraordinary] = 45;
  _resultDegrees[24][Pathetic] = 1;
  _resultDegrees[24][Mediocre] = 15;
  _resultDegrees[24][Average] = 24;
  _resultDegrees[24][Good] = 33;
  _resultDegrees[24][Excellent] = 40;
  _resultDegrees[24][Extraordinary] = 47;
  _resultDegrees[25][Pathetic] = 1;
  _resultDegrees[25][Mediocre] = 16;
  _resultDegrees[25][Average] = 25;
  _resultDegrees[25][Good] = 34;
  _resultDegrees[25][Excellent] = 41;
  _resultDegrees[25][Extraordinary] = 48;
  _resultDegrees[26][Pathetic] = 1;
  _resultDegrees[26][Mediocre] = 17;
  _resultDegrees[26][Average] = 26;
  _resultDegrees[26][Good] = 35;
  _resultDegrees[26][Excellent] = 42;
  _resultDegrees[26][Extraordinary] = 49;
  _resultDegrees[27][Pathetic] = 1;
  _resultDegrees[27][Mediocre] = 18;
  _resultDegrees[27][Average] = 27;
  _resultDegrees[27][Good] = 36;
  _resultDegrees[27][Excellent] = 43;
  _resultDegrees[27][Extraordinary] = 51;
  _resultDegrees[28][Pathetic] = 1;
  _resultDegrees[28][Mediocre] = 18;
  _resultDegrees[28][Average] = 28;
  _resultDegrees[28][Good] = 38;
  _resultDegrees[28][Excellent] = 45;
  _resultDegrees[28][Extraordinary] = 52;
  _resultDegrees[29][Pathetic] = 1;
  _resultDegrees[29][Mediocre] = 19;
  _resultDegrees[29][Average] = 29;
  _resultDegrees[29][Good] = 39;
  _resultDegrees[29][Excellent] = 46;
  _resultDegrees[29][Extraordinary] = 54;
  _resultDegrees[30][Pathetic] = 1;
  _resultDegrees[30][Mediocre] = 20;
  _resultDegrees[30][Average] = 30;
  _resultDegrees[30][Good] = 40;
  _resultDegrees[30][Excellent] = 47;
  _resultDegrees[30][Extraordinary] = 55;
  _resultDegrees[31][Pathetic] = 1;
  _resultDegrees[31][Mediocre] = 21;
  _resultDegrees[31][Average] = 31;
  _resultDegrees[31][Good] = 41;
  _resultDegrees[31][Excellent] = 48;
  _resultDegrees[31][Extraordinary] = 56;
  _resultDegrees[32][Pathetic] = 1;
  _resultDegrees[32][Mediocre] = 22;
  _resultDegrees[32][Average] = 32;
  _resultDegrees[32][Good] = 42;
  _resultDegrees[32][Excellent] = 49;
  _resultDegrees[32][Extraordinary] = 58;
  _resultDegrees[33][Pathetic] = 1;
  _resultDegrees[33][Mediocre] = 23;
  _resultDegrees[33][Average] = 33;
  _resultDegrees[33][Good] = 43;
  _resultDegrees[33][Excellent] = 51;
  _resultDegrees[33][Extraordinary] = 59;
  _resultDegrees[34][Pathetic] = 1;
  _resultDegrees[34][Mediocre] = 23;
  _resultDegrees[34][Average] = 34;
  _resultDegrees[34][Good] = 45;
  _resultDegrees[34][Excellent] = 52;
  _resultDegrees[34][Extraordinary] = 61;
  _resultDegrees[35][Pathetic] = 1;
  _resultDegrees[35][Mediocre] = 24;
  _resultDegrees[35][Average] = 35;
  _resultDegrees[35][Good] = 46;
  _resultDegrees[35][Excellent] = 53;
  _resultDegrees[35][Extraordinary] = 62;
  _resultDegrees[36][Pathetic] = 1;
  _resultDegrees[36][Mediocre] = 25;
  _resultDegrees[36][Average] = 36;
  _resultDegrees[36][Good] = 47;
  _resultDegrees[36][Excellent] = 55;
  _resultDegrees[36][Extraordinary] = 64;
  _resultDegrees[37][Pathetic] = 1;
  _resultDegrees[37][Mediocre] = 26;
  _resultDegrees[37][Average] = 37;
  _resultDegrees[37][Good] = 48;
  _resultDegrees[37][Excellent] = 56;
  _resultDegrees[37][Extraordinary] = 65;
  _resultDegrees[38][Pathetic] = 1;
  _resultDegrees[38][Mediocre] = 26;
  _resultDegrees[38][Average] = 38;
  _resultDegrees[38][Good] = 50;
  _resultDegrees[38][Excellent] = 58;
  _resultDegrees[38][Extraordinary] = 67;
  _resultDegrees[39][Pathetic] = 1;
  _resultDegrees[39][Mediocre] = 27;
  _resultDegrees[39][Average] = 39;
  _resultDegrees[39][Good] = 51;
  _resultDegrees[39][Excellent] = 59;
  _resultDegrees[39][Extraordinary] = 68;
  _resultDegrees[40][Pathetic] = 1;
  _resultDegrees[40][Mediocre] = 28;
  _resultDegrees[40][Average] = 40;
  _resultDegrees[40][Good] = 52;
  _resultDegrees[40][Excellent] = 60;
  _resultDegrees[40][Extraordinary] = 70;
  _resultDegrees[41][Pathetic] = 0;
  _resultDegrees[41][Mediocre] = 0;
  _resultDegrees[41][Average] = 0;
  _resultDegrees[41][Good] = 53;
  _resultDegrees[41][Excellent] = 0;
  _resultDegrees[41][Extraordinary] = 71;
  _resultDegrees[42][Pathetic] = 0;
  _resultDegrees[42][Mediocre] = 0;
  _resultDegrees[42][Average] = 0;
  _resultDegrees[42][Good] = 54;
  _resultDegrees[42][Excellent] = 0;
  _resultDegrees[42][Extraordinary] = 72;
  _resultDegrees[43][Pathetic] = 0;
  _resultDegrees[43][Mediocre] = 0;
  _resultDegrees[43][Average] = 0;
  _resultDegrees[43][Good] = 55;
  _resultDegrees[43][Excellent] = 0;
  _resultDegrees[43][Extraordinary] = 73;
  _resultDegrees[44][Pathetic] = 0;
  _resultDegrees[44][Mediocre] = 0;
  _resultDegrees[44][Average] = 0;
  _resultDegrees[44][Good] = 56;
  _resultDegrees[44][Excellent] = 0;
  _resultDegrees[44][Extraordinary] = 75;
  _resultDegrees[45][Pathetic] = 0;
  _resultDegrees[45][Mediocre] = 0;
  _resultDegrees[45][Average] = 0;
  _resultDegrees[45][Good] = 58;
  _resultDegrees[45][Excellent] = 0;
  _resultDegrees[45][Extraordinary] = 77;
  _resultDegrees[46][Pathetic] = 0;
  _resultDegrees[46][Mediocre] = 0;
  _resultDegrees[46][Average] = 0;
  _resultDegrees[46][Good] = 59;
  _resultDegrees[46][Excellent] = 0;
  _resultDegrees[46][Extraordinary] = 78;
  _resultDegrees[47][Pathetic] = 0;
  _resultDegrees[47][Mediocre] = 0;
  _resultDegrees[47][Average] = 0;
  _resultDegrees[47][Good] = 60;
  _resultDegrees[47][Excellent] = 0;
  _resultDegrees[47][Extraordinary] = 79;
  _resultDegrees[48][Pathetic] = 0;
  _resultDegrees[48][Mediocre] = 0;
  _resultDegrees[48][Average] = 0;
  _resultDegrees[48][Good] = 61;
  _resultDegrees[48][Excellent] = 0;
  _resultDegrees[48][Extraordinary] = 80;
  _resultDegrees[49][Pathetic] = 0;
  _resultDegrees[49][Mediocre] = 0;
  _resultDegrees[49][Average] = 0;
  _resultDegrees[49][Good] = 62;
  _resultDegrees[49][Excellent] = 0;
  _resultDegrees[49][Extraordinary] = 81;
  _resultDegrees[50][Pathetic] = 0;
  _resultDegrees[50][Mediocre] = 0;
  _resultDegrees[50][Average] = 0;
  _resultDegrees[50][Good] = 63;
  _resultDegrees[50][Excellent] = 0;
}
